<{include file="header.html"}>

<script type="text/javascript">

var cur_edited_value = "";
var cur_id = "";

function isValidDecimalNumber(str_number,max_num_of_decimal)
{
	if (max_num_of_decimal == undefined)
	{
		max_num_of_decimal = 2;
	}
	str_array = str_number.split(".");

	if (str_array[1] != undefined && str_array[1].length > max_num_of_decimal)
	{
		return false;
	}
	return true;
}

/*
* Validate before updating
* param: cur_object: ID of object contains the value should be checked
* param: param_type: PARAM_TYPE_DATETIME or PARAM_TYPE_NUMBER
*
*/
function validate(cur_object, param_type, para_name)
{
	// check whether or not the object's value is empty
	if(isEmptyTextBox(cur_object, '<{$smarty.const._LB_MUST_NOT_BE_EMPTY|utf8_escape_js}>')) {
		return false;
	}

	// check validation belong to param_type: DATETIME or NUMBER
	if(param_type == <{$smarty.const.PARAM_TYPE_DATETIME}>){
		// check validation for DATETIME
		if(!isValidDate(cur_object.value, "DMY")){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._LB_DATE_INVALID|utf8_escape_js}>');
			return false;
		}
	}else if(param_type == <{$smarty.const.PARAM_TYPE_NUMBER}>){
		// check validation for NUMBER, equal or greater than 0
		if(!isPositiveWholeInteger(cur_object.value)){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
			return false;
		}
	}else if(param_type == <{$smarty.const.PARAM_TYPE_RATE_NUMBER}>){
		// check validation for NUMBER, equal or greater than 0
		if(!isNumeric(cur_object.value)){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
			return false;
		}
		if (!isValidDecimalNumber(cur_object.value))
		{
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_DECIMAL_NUMBER|utf8_escape_js}>');
			return false;
		}
	}else if(param_type == <{$smarty.const.PARAM_TYPE_FLOAT_WITH_3_DECIMAL}>){

		if(!isNumeric(cur_object.value) || parseFloat(cur_object.value) <= 0){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
			return false;
		}
		if (!isValidDecimalNumber(cur_object.value, <{$smarty.const.MAX_DECIMAL_NUMBER_OF_TIMEOUT}>))
		{
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_DOUBLE_NUMBER|replace:"N":$smarty.const.MAX_DECIMAL_NUMBER_OF_TIMEOUT|utf8_escape_js}>');
			return false;
		}
	}else if(param_type == <{$smarty.const.PARAM_TYPE_FLOAT_WITH_2_DECIMAL}>){

		if(!isNumeric(cur_object.value) || parseFloat(cur_object.value) <= 0){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
			return false;
		}
		if (!isValidDecimalNumber(cur_object.value, 2))
		{
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_DOUBLE_NUMBER|replace:"N":"2"|utf8_escape_js}>');
			return false;
		}

	}else if(param_type == <{$smarty.const.PARAM_TYPE_POSITIVE_NUMBER}>){
		// check validation for NUMBER, greater than 0
		if(!isPositiveWholeInteger(cur_object.value) || cur_object.value <= 0){
			// show bubble message
			showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
			return false;
		}
		if (para_name == 'LEVEL_OF_PRIORITY_OF_PUBLICATION')
		{
			if (cur_object.value > 99)
			{
				// show bubble message
				showErrorBubble(cur_object, '<{$smarty.const._MSG_INVALID_NUMBER|utf8_escape_js}>');
				return false;
			}
		}
	}

	return true;
}

function showbox(id)
{
	//alert("S: curid = " + cur_id + " ---- cur_value = " + cur_edited_value);
	var box = document.getElementById("box_"+id);
	var text = document.getElementById("text_"+id);
	var text_value = document.getElementById("value_"+id);
	if( cur_id != "" && cur_id != id){
		hidebox(cur_id);
	}
	cur_edited_value = text_value.value;
	cur_id = id;
	box.style.display = "none";
	text.style.display = "";
}

function hidebox(id)
{
	var box = document.getElementById("box_"+id);
	var text = document.getElementById("text_"+id);
	var text_value = document.getElementById("value_"+id);

	if(cur_id == id){
		text_value.value = cur_edited_value;
	}

	box.style.display = "";
	text.style.display = "none";
}

function save_value(id, param_type, para_name)
{
	var val = document.getElementById("value_"+id);
	var args = new Array();

	// check validation
	if(validate(val, param_type, para_name)){
		if (param_type == <{$smarty.const.PARAM_TYPE_LIST_QUERY}> ||
			param_type == <{$smarty.const.PARAM_TYPE_LIST_WEBSERVICE}>) {
			args.push(id);
			args.push(val.value);

			var label = document.getElementById("value_"+id + "_" + val.value);
			args.push(label.innerHTML);

			if (document.getElementById("box_value_"+id).innerHTML != val.value)
				if (callFunction('Parameter::saveValue',args))
				{
					document.getElementById("box_value_"+id).innerHTML = label.innerHTML;
				}
			cur_edited_value = label.innerHTML;
			hidebox(id);
		}
		else {
			args.push(id);
			args.push(val.value);

			if (document.getElementById("box_value_"+id).innerHTML != val.value)
				if (callFunction('Parameter::saveValue',args))
				{
					if (param_type == <{$smarty.const.PARAM_TYPE_STRING_SELECTION}>)
					{
						if (val.value == <{$smarty.const.TECHNICAL_DATA_MANUAL_ENTRY}> )
						{
							document.getElementById("box_value_"+id).innerHTML = '<{$smarty.const._LB_TECHNICAL_DATA_MANUAL_ENTRY|utf8_escape_js}>';
						}
						else if (val.value == <{$smarty.const.TECHNICAL_DATA_CALCULATED_BY_THE_SYSTEM}> )
						{
							document.getElementById("box_value_"+id).innerHTML = '<{$smarty.const._LB_TECHNICAL_DATA_CALCULATED_BY_THE_SYSTEM|utf8_escape_js}>';
						}
						else
						{
							document.getElementById("box_value_"+id).innerHTML = '<{$smarty.const._LB_TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA|utf8_escape_js}>';
						}
					}
					else
					{
						document.getElementById("box_value_"+id).innerHTML = val.value;
					}
				}
			cur_edited_value = val.value;
			hidebox(id);
		}
	}
}

function switch_checkbox(id)
{
	var text = document.getElementById("text_"+id);

	if (text.style.display == "none")
		text.style.display = "";
	else
		text.style.display = "none";
}

function save_checkbox(id)
{
	var val = document.getElementById('value_'+id);
	var args = new Array();
	args.push(id);
	if (val.checked)
		args.push(1);
	else
		args.push(0);
	callFunction('Parameter::saveValue',args);
	switch_checkbox(id);
}

$(function() {
	$('#bar1').selectable({
		stop: function(){
			selectionBarOnChanged();
		}
	});
});
</script>

	<div class="box_two_third">
		<div class="tab_small">
			<{foreach from=$tabs item="group_name" key="tab" }>
				<{if $category == $tab}>
					<div class="box_head"><{$group_name|utf8_escape_html}></div>
				<{else}>
					<div onclick="window.location='<{$smarty.const.APPLICATION_URL}>/parameter/list/?category=<{$tab}>'" class="tab_inactive hand">
							<{$group_name|utf8_escape_html}></div>
				<{/if}>
			<{/foreach}>
		</div>
		<div class="box_content">
			<{while $param->fetch()}>
				<div class="object" style="padding-bottom:10px">
					<{if $param->TYPE == $smarty.const.PARAM_TYPE_BOOLEAN}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<input onclick="switch_checkbox(<{$param->ID}>)" type="checkbox" name="value_<{$param->ID}>" id="value_<{$param->ID}>"
										<{if $param->VALUE }>checked<{/if}>
										<{if !$param->canViewForm()}>
											disabled
										<{/if}>
									/>
									<a id="text_<{$param->ID}>" style="display:none" href="javascript:save_checkbox(<{$param->ID}>)" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
								</div>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_DATETIME}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<div style="display:inline" id="box_value_<{$param->ID}>"><{$param->VALUE}></div>
									<{if $param->canViewForm()}>
										<a href="javascript:showbox(<{$param->ID}>)" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									<{/if}>
								</div>

								<div id="text_<{$param->ID}>" style="display:none">
									<input id="value_<{$param->ID}>" name="value_<{$param->ID}>" value="<{$param->VALUE}>" type="text" size="10" />
									<a href="javascript:save_value(<{$param->ID}>,<{$param->TYPE}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
									<a href="javascript:hidebox(<{$param->ID}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
									</a>
								</div>
								<script type="text/javascript">
									getDatePicker('value_<{$param->ID}>');
								</script>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_LIST_QUERY ||
							 $param->TYPE == $smarty.const.PARAM_TYPE_LIST_WEBSERVICE}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<div style="display:inline" id="box_value_<{$param->ID}>"><{$param->LABEL}></div>
									<{if $param->canViewForm()}>
										<a href="javascript:showbox(<{$param->ID}>)" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									<{/if}>
								</div>

								<div id="text_<{$param->ID}>" style="display:none">
									<select id="value_<{$param->ID}>" name="value_<{$param->ID}>">
										<option id="value_<{$param->ID}>_0" value="0" selected="selected"><{$smarty.const._LB_NONE|utf8_escape_html}></option>
											<{assign var='param_id' value=$param->ID}>
											<{foreach from=$references.$param_id key=id item=v}>
												<{if $param->VALUE == $id}>
													<option id="value_<{$param_id}>_<{$id}>" value="<{$id}>" selected="selected"><{$v}></option>
												<{else}>
													<option id="value_<{$param_id}>_<{$id}>" value="<{$id}>"><{$v}></option>
												<{/if}>
											<{/foreach}>
									</select>

									<a href="javascript:save_value(<{$param->ID}>,<{$param->TYPE}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
									<a href="javascript:hidebox(<{$param->ID}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
									</a>
								</div>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_STRING_SELECTION}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<div style="display:inline" id="box_value_<{$param->ID}>">
										<{if $param->VALUE == $smarty.const.TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA}>
											<{$smarty.const._LB_TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA}>
										<{elseif $param->VALUE == $smarty.const.TECHNICAL_DATA_MANUAL_ENTRY}>
											<{$smarty.const._LB_TECHNICAL_DATA_MANUAL_ENTRY}>
										<{/if}>
									</div>
									<{if $param->canViewForm()}>
										<a href="javascript:showbox(<{$param->ID}>)" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									<{/if}>
								</div>

								<div id="text_<{$param->ID}>" style="display:none">
									<select id="value_<{$param->ID}>" name="value_<{$param->ID}>" >
										<option value="<{$smarty.const.TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA}>" <{if $param->VALUE == $smarty.const.TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA}>selected<{/if}> >
											<{$smarty.const._LB_TECHNICAL_DATA_BALANCE_BETWEEN_THE_TECHNICAL_DATA}>
										</option>
										<option value="<{$smarty.const.TECHNICAL_DATA_MANUAL_ENTRY}>" <{if $param->VALUE == $smarty.const.TECHNICAL_DATA_MANUAL_ENTRY}>selected<{/if}> >
											<{$smarty.const._LB_TECHNICAL_DATA_MANUAL_ENTRY}>
										</option>
									</select>
									<a href="javascript:save_value(<{$param->ID}>,<{$param->TYPE}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
									<a href="javascript:hidebox(<{$param->ID}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
									</a>
								</div>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_RATE_NUMBER}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<div style="display:inline" id="box_value_<{$param->ID}>">
										<{if $param->TYPE == $smarty.const.PARAM_TYPE_RATE_NUMBER}>
											<{$output->format_price($param->VALUE)}>
										<{else}>
											<{$param->VALUE}>
										<{/if}>

									</div>
									<{if $param->canViewForm()}>
										<a href="javascript:showbox(<{$param->ID}>)" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									<{/if}>
								</div>

								<div id="text_<{$param->ID}>" style="display:none">
									<input id="value_<{$param->ID}>" name="value_<{$param->ID}>" value="<{if $param->TYPE == $smarty.const.PARAM_TYPE_RATE_NUMBER}><{$output->format_price($param->VALUE)}><{else}><{$param->VALUE}><{/if}>" type="text" size="10" />
									<a href="javascript:save_value(<{$param->ID}>,<{$param->TYPE}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
									<a href="javascript:hidebox(<{$param->ID}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
									</a>
								</div>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_DAY_OF_WEEK}>
						<div class="head" style="min-height:22px">
							<div>
								<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
								<{$param->SHORT_DESCRIPTION}>

								<{if $param->canViewForm()}>
									<div id="box_<{$param->ID}>" style="display:none; float: right">
										<a href="javascript:save_day_of_week();" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
										</a>
										<a href="javascript:close_day_of_week()" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
										</a>
									</div>

									<div id="text_<{$param->ID}>" style="float: right">
										<a href="javascript:show_day_of_week()" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									</div>
									<div style="clear:right"></div>
								<{/if}>
							</div>
							<div class="content">
								<div>
									<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
								</div>
								<div style="text-align:right">
									<div id="obj_day_week">
										<input type="checkbox" value="1" name="objective_day_of_week[]" id="objective_day_of_week_1" onchange="show_day_of_week()" /><{$smarty.const._LB_MONDAY|utf8_escape_html}>
										<input type="checkbox" value="2" name="objective_day_of_week[]" id="objective_day_of_week_2" onchange="show_day_of_week()" /><{$smarty.const._LB_TUESDAY|utf8_escape_html}>
										<input type="checkbox" value="3" name="objective_day_of_week[]" id="objective_day_of_week_3" onchange="show_day_of_week()" /><{$smarty.const._LB_WEDNESDAY|utf8_escape_html}>
										<input type="checkbox" value="4" name="objective_day_of_week[]" id="objective_day_of_week_4" onchange="show_day_of_week()" /><{$smarty.const._LB_THURSDAY|utf8_escape_html}>
										<input type="checkbox" value="5" name="objective_day_of_week[]" id="objective_day_of_week_5" onchange="show_day_of_week()" /><{$smarty.const._LB_FRIDAY|utf8_escape_html}>
										<input type="checkbox" value="6" name="objective_day_of_week[]" id="objective_day_of_week_6" onchange="show_day_of_week()" /><{$smarty.const._LB_SATURDAY|utf8_escape_html}>
										<input type="checkbox" value="0" name="objective_day_of_week[]" id="objective_day_of_week_0" onchange="show_day_of_week()" /><{$smarty.const._LB_SUNDAY|utf8_escape_html}>
									</div>

									<script type="text/javascript">
										//show the Day Of Week optional Objective if any
										var dow = [<{$param->VALUE}>];
										<{if $param->VALUE}>
											for (var i = 0 ; i < dow.length ; i++ )
											{
												document.getElementById('objective_day_of_week_' + dow[i]).checked = true;
											}
										<{/if}>

										function show_day_of_week(){
											<{if $param->canViewForm()}>
												document.getElementById('box_<{$param->ID}>').style.display = '';
												document.getElementById('text_<{$param->ID}>').style.display = 'none';
											<{/if}>
										}
										function close_day_of_week(){
											for (var i = 0 ; i < 7 ; i++ )
											{
												is_check = false;
												for (var j = 0 ; j < dow.length ; j++ )
													if (i == dow[j]){
														is_check = true; break;
													}
												document.getElementById('objective_day_of_week_' + i).checked = is_check;
											}

											document.getElementById('box_<{$param->ID}>').style.display = 'none';
											document.getElementById('text_<{$param->ID}>').style.display = '';
										}

										function save_day_of_week(){

											<{if $param->canViewForm()}>

											value = '';
											for (var i = 0 ; i < 7 ; i++ )
											{
												if (document.getElementById('objective_day_of_week_' + i).checked){
													if (value != '')
														value = value + ',';
													value = value + i;
												}
											}
											dow = value.split(',');

											var args = new Array();
											args.push(<{$param->ID}>);
											args.push(value);

											callFunction('Parameter::saveValue',args);

											document.getElementById('box_<{$param->ID}>').style.display = 'none';
											document.getElementById('text_<{$param->ID}>').style.display = '';

											<{/if}>
										}
									</script>
								</div>
							</div>
						</div>

					<{elseif $param->TYPE == $smarty.const.PARAM_TYPE_HOUR_OF_DAY}>
						<div class="head" style="min-height:22px">
							<div>
								<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
								<{$param->SHORT_DESCRIPTION}>

								<{if $param->canViewForm()}>
									<div id="box_<{$param->ID}>" style="display:none; float: right">
										<a href="javascript:save_hour_of_day();" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
										</a>
										<a href="javascript:close_hour_of_day()" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
										</a>
									</div>

									<div id="text_<{$param->ID}>" style="float: right">
										<a href="javascript:show_hour_of_day()" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									</div>
									<div style="clear:right"></div>
								<{/if}>
							</div>
							<div class="content">
								<div>
									<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
								</div>
								<div style="text-align:right">
									<div class="left" id="obj_time_day" style="padding-top: 15px">
										<div class="label_bar"><{$smarty.const._LB_CAMPAGNE_TIME_OF_DAY1|utf8_escape_html}></div>
										<div class="label_bar" style="margin-left: 180px;"><{$smarty.const._LB_CAMPAGNE_TIME_OF_DAY2|utf8_escape_html}></div>
										<div class="label_bar" style="margin-left: 180px;"><{$smarty.const._LB_CAMPAGNE_TIME_OF_DAY3|utf8_escape_html}></div>
										<div class="label_bar" style="margin-left: 180px;"><{$smarty.const._LB_CAMPAGNE_TIME_OF_DAY1|utf8_escape_html}></div>

										<ol id="bar1" class="timebar">
											<li class="ui-state-default" value="0" id="li0"></li>
											<li class="ui-state-default" value="1" id="li1"></li>
											<li class="ui-state-default" value="2" id="li2"></li>
											<li class="ui-state-default" value="3" id="li3"></li>
											<li class="ui-state-default" value="4" id="li4"></li>
											<li class="ui-state-default" value="5" id="li5"></li>
											<li class="ui-state-default" value="6" id="li6"></li>
											<li class="ui-state-default" value="7" id="li7"></li>
											<li class="ui-state-default" value="8" id="li8"></li>
											<li class="ui-state-default" value="9" id="li9"></li>
											<li class="ui-state-default" value="10" id="li10"></li>
											<li class="ui-state-default" value="11" id="li11"></li>
											<li class="ui-state-default" value="12" id="li12"></li>
											<li class="ui-state-default" value="13" id="li13"></li>
											<li class="ui-state-default" value="14" id="li14"></li>
											<li class="ui-state-default" value="15" id="li15"></li>
											<li class="ui-state-default" value="16" id="li16"></li>
											<li class="ui-state-default" value="17" id="li17"></li>
											<li class="ui-state-default" value="18" id="li18"></li>
											<li class="ui-state-default" value="19" id="li19"></li>
											<li class="ui-state-default" value="20" id="li20"></li>
											<li class="ui-state-default" value="21" id="li21"></li>
											<li class="ui-state-default" value="22" id="li22"></li>
											<li class="ui-state-default" value="23" id="li23"></li>
											<li class="ui-state-default" value="24" id="li24"></li>
											<li class="ui-state-default" value="25" id="li25"></li>
											<li class="ui-state-default" value="26" id="li26"></li>
											<li class="ui-state-default" value="27" id="li27"></li>
											<li class="ui-state-default" value="28" id="li28"></li>
											<li class="ui-state-default" value="29" id="li29"></li>
											<li class="ui-state-default" value="30" id="li30"></li>
											<li class="ui-state-default" value="31" id="li31"></li>
											<li class="ui-state-default" value="32" id="li32"></li>
											<li class="ui-state-default" value="33" id="li33"></li>
											<li class="ui-state-default" value="34" id="li34"></li>
											<li class="ui-state-default" value="35" id="li35"></li>
											<li class="ui-state-default" value="36" id="li36"></li>
											<li class="ui-state-default" value="37" id="li37"></li>
											<li class="ui-state-default" value="38" id="li38"></li>
											<li class="ui-state-default" value="39" id="li39"></li>
											<li class="ui-state-default" value="40" id="li40"></li>
											<li class="ui-state-default" value="41" id="li41"></li>
											<li class="ui-state-default" value="42" id="li42"></li>
											<li class="ui-state-default" value="43" id="li43"></li>
											<li class="ui-state-default" value="44" id="li44"></li>
											<li class="ui-state-default" value="45" id="li45"></li>
											<li class="ui-state-default" value="46" id="li46"></li>
											<li class="ui-state-default" value="47" id="li47"></li>
										</ol>

										<input type="hidden" name="objective_time_of_day" id="objective_time_of_day" value="<{$param->VALUE}>" />
									</div>

									<div class="right" id="selection_bar_display" style="padding-top: 10px; min-width:160px;"></div>

									<script type="text/javascript">
										//create time of day selection bar control
										var arr_period_range = [];

										// global variable containing default data of time of day
										var tod = [<{$param->VALUE}>];
										loadTODBar();

										// reload default data of Time Of Day
										function loadTODBar()
										{
											for (var i = 0; i < tod.length; i++)
											{
												document.getElementById('li' + tod[i]).className = 'ui-state-default ui-selectee ui-selected';
											}

											document.getElementById('selection_bar_display').innerHTML = convertTimeDayToString(tod);
										}

										// reset all data
										function resetTODBar()
										{
											var total_slot = 48;
											for (var i = 0; i < total_slot; i++)
											{
												document.getElementById('li' + i).className = 'ui-state-default';
											}

											document.getElementById('selection_bar_display').innerHTML = convertTimeDayToString(tod);
										}

										function selectionBarOnChanged(is_display)
										{
											var time_group = document.getElementsByTagName('li');
											var time_day = [];
											for (var i = 0; i < time_group.length; i++)
											{
												if (time_group[i].className == 'ui-state-default ui-selectee ui-selected')
												{
													time_day.push(time_group[i].value);
												}
											}
											document.getElementById('objective_time_of_day').value = time_day.join(',');

											document.getElementById('selection_bar_display').innerHTML = convertTimeDayToString(time_day);

											//mergeTOD();
											//$('selection_bar_display').innerHTML = convertTimeDayToString(time_day);

											if (!is_display)
												show_hour_of_day();
										}

										function convertTimeDayToString(selectedValues)
										{
											var tmp = [];
											for( var i = 0; i < selectedValues.length; i++ )
												tmp.push(selectedValues[i], selectedValues[i] + 1);

											var tmp_new = [];
											for( var i = 0 ; i < tmp.length; i++ )
												if( tmp[i] == tmp[i+1] )
												{
													i++;
												}
												else
												{
													tmp_new.push(tmp[i]);
												}

											tmp = tmp_new;
											var str = new String();
											var j = false;
											for( var i = 0 ; i < tmp.length; i++ )
											{
												if( tmp[i] != undefined )
												{
													var hours;
													var minnutes;
													if( parseInt(tmp[i]) % 2 == 1)
													{
														hours = (tmp[i] - 1)/2;
														minnutes = '30';
													}
													else
													{
														hours = (tmp[i])/2;
														minnutes = '00';
													}

													var tmp_string = (hours < 10 ? '0':'') + hours + ':' + minnutes;

													if( j )
													{
														str += tmp_string + '<\/span>';
														j = false;
													}
													else
													{
														str += '<span class="date_time_display" style="display: block">de '+ tmp_string + ' &agrave ';
														j = true;
													}
												}
											}
											return str;
										}

										function show_hour_of_day(){
											<{if $param->canViewForm()}>
												document.getElementById('box_<{$param->ID}>').style.display = '';
												document.getElementById('text_<{$param->ID}>').style.display = 'none';
											<{/if}>
										}

										function close_hour_of_day(){
											var time_day = document.getElementById('objective_time_of_day').value.split(',');

											splitTOD(time_day);
											selectionBarOnChanged(1);

											resetTODBar();
											loadTODBar();

											document.getElementById('box_<{$param->ID}>').style.display = 'none';
											document.getElementById('text_<{$param->ID}>').style.display = '';
										}

										function save_hour_of_day(){
											<{if $param->canViewForm()}>
											var time_day = document.getElementById('objective_time_of_day').value;
											document.getElementById('objective_time_of_day').value = time_day;

											value = document.getElementById('objective_time_of_day').value;

											var args = new Array();
											args.push(<{$param->ID}>);
											args.push(value);

											callFunction('Parameter::saveValue',args);

											document.getElementById('box_<{$param->ID}>').style.display = 'none';
											document.getElementById('text_<{$param->ID}>').style.display = '';

											<{/if}>
										}

										function splitTOD(arrayValues)
										{
											time_day_1 = [];
											time_day_2 = [];
											time_day_3 = [];

											for( var i = 0; i < arrayValues.length; i++ )
											{
												var a = parseInt(arrayValues[i]);

												if( a >= 0 && a < 16)
												{
													time_day_1.push(a);
												}
												else if( a >= 16 && a < 32 )
													time_day_2.push(a);
												else
													time_day_3.push(a);
											}

										}

										function mergeTOD()
										{
											time_day = time_day_1.concat(time_day_2.concat(time_day_3));

											for( var i = 0 ; i < time_day.length; i++ )
											{
												time_day[i] = parseInt(time_day[i]);
											}

											for( var i = 0 ; i < time_day.length - 1; i++ )
											{
												for( var j = i + 1; j < time_day.length; j++ )
												{
													if( time_day[i] > time_day[j])
													{
														var tmp = time_day[i];
														time_day[i] = time_day[j];
														time_day[j] = tmp;
													}
												}
											}
										}

									</script>
									<div style="clear:both"></div>
								</div>
							</div>
						</div>
					<{else}>
						<div class="head" style="min-height:22px">
							<div class="right">
								<div id="box_<{$param->ID}>">
									<div style="display:inline" id="box_value_<{$param->ID}>"><{$param->VALUE}></div>
									<{if $param->canViewForm()}>
										<a href="javascript:showbox(<{$param->ID}>)" >
											<{$html_input->image_tooltip("", $smarty.const._IMAGE_MODIFIER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_EDIT)}>
										</a>
									<{/if}>
								</div>

								<div id="text_<{$param->ID}>" style="display:none">
									<input id="value_<{$param->ID}>" name="value_<{$param->ID}>" value="<{$param->VALUE}>" type="text" size="10" />
									<a href="javascript:save_value(<{$param->ID}>,<{$param->TYPE}>,'<{$param->NOM}>');" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_DONE, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_VALIDATE)}>
									</a>
									<a href="javascript:hidebox(<{$param->ID}>);" >
										<{$html_input->image_tooltip("", $smarty.const._IMAGE_SUPPRIMER, $smarty.const.IMAGE_SIZE_SMALL, $smarty.const._LB_CANCEL)}>
									</a>
								</div>
							</div>
							<img class="small" src="<{$smarty.const.APPLICATION_URL}>/images/<{$smarty.const.IMAGE_NAME_PARAMETER_SMALL}>" alt="" />
							<{$param->SHORT_DESCRIPTION}>
						</div>
						<div class="content">
							<{$smarty.const._LB_DESCRIPTION|utf8_escape_html}> : <{$param->DESCRIPTION}>
						</div>
					<{/if}>
					<div class="clear"></div>
				</div>
			<{/while}>
			<div class="clear"></div>
		</div>

	</div>

<{include file="footer.html"}>
